package com.pinancial.common.vo;

/**
 * @author: 周未
 * @Description:
 * @create 16:16 2019/12/30
 */

import com.pinancial.common.constants.ResultCodeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;
import java.util.Map;

@Data
@ApiModel (value = "全局统一返回结果")
public class Result {
	@ApiModelProperty (value = "是否成功")
	private Boolean success;
	@ApiModelProperty (value = "返回码")
	private Integer code;
	@ApiModelProperty (value = "返回消息")
	private String message;

	@ApiModelProperty (value = "返回数据")
	private Object result;

	private Result() {
	}

	public static Result ok() {
		Result r = new Result();
		r.setSuccess(ResultCodeEnum.SUCCESS.getSuccess());
		r.setCode(ResultCodeEnum.SUCCESS.getCode());
		r.setMessage(ResultCodeEnum.SUCCESS.getMessage());
		return r;
	}

	public static Result error() {
		Result r = new Result();
		r.setSuccess(ResultCodeEnum.FAILURE.getSuccess());
		r.setCode(ResultCodeEnum.FAILURE.getCode());
		r.setMessage(ResultCodeEnum.FAILURE.getMessage());
		return r;
	}

	public static Result setResult(ResultCodeEnum resultCodeEnum) {
		Result r = new Result();
		r.setSuccess(resultCodeEnum.getSuccess());
		r.setCode(resultCodeEnum.getCode());
		r.setMessage(resultCodeEnum.getMessage());
		return r;
	}

	public Result success(Boolean success) {
		setSuccess(success);
		return this;
	}

	public Result message(String message) {
		setMessage(message);
		return this;
	}

	public Result code(Integer code) {
		setCode(code);
		return this;
	}

	public Result result(Object result) {
		this.result = result;
		return this;
	}

	public Result result(Map<String, Object> map) {
		result = map;
		return this;
	}

	public Result result(List list) {
		result = list;
		return this;
	}

	public Result result(Object... objects) {
		result = objects;
		return this;
	}

}

